package com.ydd.controller.user;

import com.baomidou.mybatisplus.extension.api.R;
import com.ydd.dto.*;
import com.ydd.result.Result;
import com.ydd.service.UserService;
import com.ydd.vo.ArticlePageListVO;
import com.ydd.vo.UserArticleVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description TODO
 * @Author itheima
 * @Date 2023-05-02 22:36
 */
@Slf4j
@Api(tags = "前台用户相关接口")
@RequestMapping("/user")
@RestController
public class UserController {
    @Autowired
    private UserService userService;


    /**
     * 我的文章接口
     *
     * @param userArticleRequestDTO
     * @return
     */
    @ApiOperation("我的文章接口")
    @GetMapping("/myArticle")
    public Result<UserArticleVO> myArticle(UserArticleRequestDTO userArticleRequestDTO) {
        log.info("我的文章");
        UserArticleVO userArticleVO = userService.myArticle(userArticleRequestDTO);
        return Result.success(userArticleVO);
    }

    /**
     * 我的收藏/点赞文章接口
     *
     * @return
     */
    @ApiOperation("我的收藏/点赞文章")
    @GetMapping("/userDataList")
    public Result<ArticlePageListVO> userDataList(UserDataListDTO userDataListDTO) {
        log.info("我的收藏/点赞文章:{}", userDataListDTO);
        ArticlePageListVO articlePageListVO = userService.userDataList(userDataListDTO);
        return Result.success(articlePageListVO);
    }


    /**
     * 新增文章
     *
     * @param editArticleDTO
     * @return
     */
    @ApiOperation("新增文章")
    @PostMapping("/editArticle")
    public Result editArticle(@RequestBody EditArticleDTO editArticleDTO) {
        log.info("新增文章:{}", editArticleDTO);
        userService.editArticle(editArticleDTO);
        return Result.success();
    }

    @ApiOperation("修改用户资料")
    @PostMapping("/update")
    public Result update(@RequestBody UserUpdateDTO userUpdateDTO) {
        log.info("修改用户资料");
        userService.update(userUpdateDTO);
        return Result.success();
    }

    /**
     * 发布文章
     *
     * @param addArticleDTO
     * @return
     */
    @ApiOperation("发布文章")
    @PostMapping("/addArticle")
    public Result addArticle(@RequestBody AddArticleDTO addArticleDTO) {
        log.info("发布文章:{}", addArticleDTO);
        userService.addArticle(addArticleDTO);
        return Result.success();
    }

    /**
     * 删除我的文章
     * @param id
     * @return
     */
    @ApiOperation("删除我的文章")
    @GetMapping("/delArticle")
    public Result delArticle(String id) {
        log.info("删除我的文章:{}", id);
        userService.delArticle(id);
        return Result.success();
    }


    @ApiOperation("点赞/取消点赞和收藏/取消收藏")
    @GetMapping("/userDataHandle")
    public Result userDataHandle(UserDataHandleDTO userDataHandleDTO){
        log.info("点赞/取消点赞和收藏/取消收藏:{}",userDataHandleDTO);
        userService.userDataHandle(userDataHandleDTO);
        return Result.success();
    }


}
